<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增项目')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<style>
    input.editable-select {
        background: #FFFFFF url("http://60.172.168.121:8877/img/arrow-down.gif") right center no-repeat;
        padding: 6px 16px;
        width: 100% !important;
        border: 1px solid #e5e6e7;
    }

    .editable-select-options {
        position: absolute;
        display: none;
        overflow: auto;
        padding: 0;
        background: #FFF;

        z-index: 10;
        width: 59.69% !important;
    }

    .editable-select-iframe {
        position: absolute;
        background: #FFF;
        z-index: 9;
        display: none;
    }

    .editable-select-options ul {
        margin: 0;
        padding: 0;
        z-index: 10;
        list-style: none;
        list-style-image: none;
        border: 1px solid #BDCDE9;
    }

    .editable-select-options li {
        cursor: default;
        padding: 2px 16px;
    }

    .editable-select-options li.selected {
        background: #1E90FF;
        color: #fff;
    }

</style>
<body>
<div class="wrapper wrapper-content animated fadeInRight ibox-content" id="dv">
    <form class="form-horizontal m" id="form-previousCollection-add" AUTOCOMPLETE="OFF">
        <h4 class="form-header h4">基本信息</h4>
        <div class="form-group">
            <label class="col-sm-3 control-label">工程公司：</label>
            <div class="col-sm-8">
                <select name="compId" id="compId" class="form-control noselect2">
                    <option value="">请选择</option>
                    <option th:each="pro:${userComp}" th:value="${pro.compId}"
                            th:text="${pro.compName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">项目名称：</label>
            <input type="hidden" id="oid" name="oid">
            <div class="col-sm-8" style="position: relative">
                <input type="text" class="form-control noselect2 shows" >
                <div id="inputselect">

                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工程负责人：</label>
            <div class="col-sm-8">
                <input name="gcPerson" id="gcPerson" class="form-control" type="text" placeholder="请输入工程负责人">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">商务负责人：</label>
            <div class="col-sm-8">
                <input id="swPerson" name="swPerson" class="form-control" type="text" placeholder="请输入商务负责人">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同额：</label>
            <div class="col-sm-8">
                <input id="contractAmount" name="contractAmount" class="form-control" type="text" placeholder="请输入合同额">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">往期回款<span style="color: red">(万元)</span>：</label>
            <div class="col-sm-8">
                <input id="previousCollection" name="previousCollection" class="form-control" type="text"
                       placeholder="请输入往期回款">
            </div>
        </div>


    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: jqueryEditableSelect-js"/>
<script type="text/javascript">
    var prefix = ctx + "previousCollection";
    var prefixs = ctx + "outPutValue";
    var data;
    var html;
    var value;
    var compId;
    $(function () {
        $("#compId").change(function () {
            $(".shows").hide();
            compId = $("#compId option:selected").val();
            $.ajax({
                url: prefixs + '/findProByCompId',
                data: {
                    "compId": compId
                },
                success: function (data) {
                    $("#proName").remove();
                    var str = '<select id="proName" name="proName" class="form-control noselect2" style="width: 100% !important;">';
                    str += '<option title="请选择" value="">' + "请选择" + '</option>';
                    for (var i in data.data) {
                        html = data.data[i].pro_name;
                        value = data.data[i].id;

                        str += '<option title="' + html + '" value="' + value + '">' + html + '</option>';
                    }
                    str += '</select>';
                    $("#inputselect").html(str);
                    $("#proName").editableSelect({
                        bg_iframe: false,
                        case_sensitive: false,
                        items_then_scroll: 10,
                        isFilter: false,
                        effects: 'slide',
                        onSelect: function () {
                            if ($("#proName").val() != "") {
                                $.ajax({
                                    url: ctx + 'outPutValue/findOutPutValueById',
                                    data: {
                                        "oid": $("#proName").val()
                                    },
                                    success: function (data) {
                                        console.log(data);
                                        $("#gcPerson").val(data.data.gcPerson);
                                        $("#swPerson").val(data.data.swPerson);
                                        $("#contractAmount").val(data.data.contractAmount);
                                    }
                                })
                            }
                        }
                    });
                }
            })
        });
    })


    function submitHandler() {
        data = {
            "compId": $("#compId").val(),
            "oid": ($("#proName").val() == -1 ? '' : $("#proName").val()),
            "proName": ($("#proName_hidden_select option:selected").attr('title')=="请选择"?$("input[name='proName_sele']").val():$("#proName_hidden_select option:selected").attr('title')),
            "gcPerson": $("#gcPerson").val(),
            "swPerson": $("#swPerson").val(),
            "contractAmount": $("#contractAmount").val(),
            "previousCollection": $("#previousCollection").val(),
        }
        if ($("#compId").val() == "" || ($("#oid").val() == "" && $("#proName").val() == "")) {
            alert("请填写工程公司或者项目名称！");
        } else {
            $.operate.save(prefix + "/add", data);
        }
    }
</script>
</div>
</body>
</html>